export default {
  getItem(key) {
    return window.localStorage.getItem(key)
  },

  setItem(key, str) {
    window.localStorage.setItem(key, str)
  },

  delItem(key) {
    window.localStorage.removeItem(key)
  },

  getJsonItem(key) {
    let item = this.getItem(key)
    if (item) {
      return JSON.parse(item)
    } else {
      return null
    }
  },

  setObjItem(key, obj) {
    this.setItem(key, JSON.stringify(obj))
  },

  getUser() {
    return this.getJsonItem('user')
  },

  setUser(obj) {
    this.setObjItem('user', obj)
  },

  delUser() {
    this.delItem('user')
  },

  getMenus() {
    let user = this.getUser()
    if (user) {
      return user.menus
    } else {
      return null
    }
  },

  getToken() {
    let user = this.getUser()
    if (user) {
      return user.token
    } else {
      return null
    }
  },
  listDictionary(key) {
    let arr = []
    let user = this.getUser()
    if (user && user.dictionary && user.dictionary[key] && user.dictionary[key].length) {
      arr = user.dictionary[key]
    }
    return arr
  }
}
